package com.example.a20112.ui_demo.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.a20112.ui_demo.R;
import com.example.a20112.ui_demo.adapter.ShopAdapter;
import com.example.a20112.ui_demo.beans.ShopBean;
import com.example.a20112.ui_demo.listener.RetrofitListener;
import com.example.a20112.ui_demo.model.UserModel;

import java.util.List;



public class  ShopFragment extends BaseFragment implements RetrofitListener<List<ShopBean>> {
    private RecyclerView recyclerView;
    private ShopAdapter shopAdapter;

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        recyclerView=(RecyclerView) view.findViewById(R.id.shop_list);

        initData();
        initEvents();
        initViews();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_shop, container, false);
    }

    void initViews(){
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));//布局
        recyclerView.addItemDecoration(new DividerItemDecoration(getContext(),DividerItemDecoration.VERTICAL));//分割线

    }
    void initData(){
        UserModel shopModel=new UserModel();
        shopModel.getAllShops(this);
    }

    @Override
    public void onSuccess(List<ShopBean> shopBeans, int flag) {
        shopAdapter=new ShopAdapter(getActivity(),shopBeans);
        recyclerView.setAdapter(shopAdapter);

    }



    @Override
    public void onFail() {
        Toast.makeText(getContext(),"网络连接失败", Toast.LENGTH_LONG).show();

    }
    void initEvents(){


    }

}
